//
//  TFNavigationController.swift
//  weiboSina
//
//  Created by admin on 15/12/28.
//  Copyright © 2015年 admin. All rights reserved.
//

import UIKit

class TFNavigationController: UINavigationController {
    
    
    
    override func viewDidLoad() {
        super.viewDidLoad()
        
        // Do any additional setup after loading the view.
    }
    
    override func pushViewController(viewController: UIViewController, animated: Bool) {
        
        // 如果当前里面有控制器，才执行下面的逻辑
        if childViewControllers.count > 0 {
            
            var title = "返回"
            
            if childViewControllers.count == 1 {
                //正要往里面添加第二个控制器
                title = childViewControllers.first?.title ?? "返回"
            }
            // push第二个或者以后控制器隐藏底部tabBar
            viewController.hidesBottomBarWhenPushed = true
            // 设置左边item
            viewController.navigationItem.leftBarButtonItem = UIBarButtonItem(imageName: "navigationbar_back_withtext", title: title, target: self, action: "back")
            
        }
        super.pushViewController(viewController, animated: animated)
    }
    
    @objc private func back(){
        popViewControllerAnimated(true)
    }
    
    

}
